package com.chenfan.mcn.enums;

/**
 * 折扣审批单 字段获取对应名称
 * @author lizhejin
 */
public enum DiscountApprovalEnum {

    /**
     * 折扣审批单 状态
     * 优惠形式:0_仅平台返点,1_年度优惠含平台返点,2_年度优惠不含平台返点,3_仅年度优惠
     */
    SINGLE_DISCOUNT("approvalType", 0, "单笔优惠"),
    YEAR_DISCOUNT("approvalType", 1, "年度优惠"),
    PLATFORM_DISCOUNT("discountType", 0, "仅平台返点"),
    YEAR_WITH_PLATFORM_DISCOUNT("discountType", 1, "年度优惠含平台返点"),
    YEAR_NOT_WITH_PLATFORM_DISCOUNT("discountType", 2, "年度优惠不含平台返点"),
    YEAR_TYPE_DISCOUNT("discountType", 3, "仅年度优惠");

    private final String field;
    private final int code;
    private final String statusName;

    DiscountApprovalEnum(String field, int code, String statusName) {
        this.field = field;
        this.code = code;
        this.statusName = statusName;
    }
    public int code() {
        return this.code;
    }
    public String filed() {
        return this.field;
    }
    public static String getStatusName ( String field, int code ) {
        for(DiscountApprovalEnum status : DiscountApprovalEnum.values()){
            if(status.field.equals(field) && status.code == code) {
                return status.statusName;
            }
        }
        return null;
    }

    public static boolean rebateCheck( int code ) {
        return code == DiscountApprovalEnum.PLATFORM_DISCOUNT.code() || code == DiscountApprovalEnum.YEAR_WITH_PLATFORM_DISCOUNT .code()
                || code == DiscountApprovalEnum.YEAR_NOT_WITH_PLATFORM_DISCOUNT.code();
    }

    public static boolean rangeCheck( int code ) {
        return code == DiscountApprovalEnum.YEAR_TYPE_DISCOUNT.code() || code == DiscountApprovalEnum.YEAR_WITH_PLATFORM_DISCOUNT .code()
                || code == DiscountApprovalEnum.YEAR_NOT_WITH_PLATFORM_DISCOUNT.code();
    }

    public static DiscountApprovalEnum getByCode(String field, int code) {
        for (DiscountApprovalEnum value : DiscountApprovalEnum.values()) {
            if (field.equals(value.field) && code == value.code) {
                return value;
            }
        }
        return null;
    }
}
